//index.js
const app = getApp();

Page({
  data: {
    mask:false,
    setstop: wx.getStorageSync('shopState'), //停用操作
    shouyi: '0.00',
    yue: '0.00',
    jiaoyimima: 1, //1没有2已设置
    isOverShare: true,
    shopname:wx.getStorageSync("shopName"),
    username:wx.getStorageSync("userName")
  },
  //
  openmask(){
    this.setData({
      mask: true
    })
  },
  closemask() {
    this.setData({
      mask: false
    })
  },
  // 获取首页信息
  getindexinfo() {
    let that = this
    wx.request({
      url: app.globalData.myurl,
      data: {
        cmd: "homePageData",
        userId: wx.getStorageSync('userId'),
      },
      header: {
        "content-type": "application/x-www-form-urlencoded",
        "token": wx.getStorageSync('token')
      },
      success(res) {
        console.log(res, '首页信息')
        if (res.data.zjstate == 1) {
          setTimeout(function() {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function() {
            wx.showModal({
              title: '您的账号已在其他设备登录，请重新登录！',
              showCancel: false, //是否显示取消按钮-----》false去掉取消按钮
              success: function(res) {
                if (res.confirm) {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                } else {
                  wx.clearStorageSync()
                  wx.reLaunch({
                    url: '/pages/login/login',
                  })
                }
              }
            })
          }, 0)
          return
        }
        if (res.data.result == 1) {
          setTimeout(function() {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          setTimeout(function() {
            wx.showToast({
              title: res.data.resultNote,
              icon: 'none',
              duration: 1500
            })
          }, 0)
        } else {
          wx.setStorageSync("shopId", res.data.shopId);
          wx.setStorageSync("userName", res.data.name);
          wx.setStorageSync("shopState", res.data.shopState);
          wx.setStorageSync("telephone", res.data.telephone);
          wx.setStorageSync("shopImg", res.data.shopImg);
          wx.setStorageSync("shopName", res.data.shopName);
          wx.setStorageSync("yue", res.data.balance);
          wx.setStorageSync("paypasswordtype", res.data.type);
          wx.setStorageSync("kefuRcftocken", res.data.custSerRcToken);
          that.setData({
            shouyi: res.data.todayIncome,
            yue: res.data.balance,
            jiaoyimima: res.data.type
          })
          setTimeout(function() {
            wx.hideLoading()
            wx.stopPullDownRefresh() //停止下拉刷新
          }, 0)
          // ******************************加赋值.收益 金额 是否设置交易密码
        }
      },
      fail(err) {
        setTimeout(function() {
          wx.hideLoading()
          wx.stopPullDownRefresh() //停止下拉刷新
        }, 0)
        setTimeout(function() {
          wx.showToast({
            title: '网络错误，稍后重试',
            icon: 'none',
            duration: 1500
          })
        }, 0)
      }
    });
  },
  //去收益界面
  toshouyi() {
    wx.navigateTo({
      url: '/pages/setting/page/jinrishouyi/jinrishouyi',
    })
  },
  //去余额
  toyue() {
    let that = this
    if(that.data.setstop == 0){
      wx.navigateTo({
        url: '/pages/setting/page/yuetixian/yuetixian',
      })
    }else{
      wx.showToast({
        icon:'none',
        title: '您的店铺已停用，无权进行此操作！',
      })
      return
    }
    
  },
  //去分类设置
  tofenlei() {
    wx.navigateTo({
      url: '/pages/setting/page/fenleishezhi/fenleishezhi',
    })
  },
  //去广告设置
  toguangao() {
    wx.navigateTo({
      url: '/pages/setting/page/guanggaoshezhi/guanggaoshezhi',
    })
  },
  //去2人团发布
  togoodstwoPt(){
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/twopinGoods/twopinGoods',
    })
  },
  //去普通商品发布
  togoodsPt() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/putongGoods/putongGoods',
    })
  },
  //去限时商品发布
  togoodsXs() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/xianshiGoods/xianshiGoods',
    })
  },
  //去满减商品发布
  togoodsMj() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/manjianGoods/manjianGoods',
    })
  },
  //去大众拼团发布
  togoodsTg() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/tuangouGoods/tuangouGoods',
    })
  },
  //去满送商品发布
  togoodsMs() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/mansongGoods/mansongGoods',
    })
  },
  //去代销商品发布
  togoodsDx() {
    wx.navigateTo({
      url: '/pages/goods/page/goodsShenhe/daixiaoGoods/daixiaoGoods'
    })
  },
  onLoad: function(options) {
    setTimeout(function() {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    wx.request({
      url: app.globalData.myurl, //自己的服务接口地址
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        cmd: 'updateUserSig',
        userId: wx.getStorageSync('userId')
      },
      success: function success(ress) {
        console.log(ress);
        if (ress.data.result == 1) {
          wx.showToast({
            title: ress.data.resultNote,
            icon:"none",
            duration:1500
          })
        } else {
          // wx.setStorageSync("rctoken", rctoken);
          wx.setStorageSync('userSig', ress.data.userSig)
        }


      }
    });
    // let setstop = wx.getStorageSync('shopState');
    // console.log(setstop)
    // if(setstop == 1){
    //   this.setData({
    //     setstop:false
    //   })
    // }
  },
  onShow: function() { //页面显示执行
    let that = this
    that.getindexinfo()
    // that.webimLogin()
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    setTimeout(function() {
      wx.showLoading({
        title: '加载中',
      })
    }, 0)
    let that = this
    that.getindexinfo()
    // wx.showNavigationBarLoading() //在标题栏中显示加载
    // console.log('下拉舒心')
    // setTimeout(function() {
    //   that.getindexinfo()
    //   wx.hideNavigationBarLoading() //完成停止加载
    //   wx.stopPullDownRefresh() //停止下拉刷新
    // }, 1500);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    console.log('上拉')
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    return {
      title: wx.getStorageSync('shopName'),
      path: "/pages/shopping/shopxq/shopxq?shopid=" + wx.getStorageSync('shopId'), // 路径，传递参数到指定页面。
      // imageUrl:'../../../images/logo/LOGO.png'
      imageUrl: wx.getStorageSync('shopImg')
    }
  },
})